<?php 

define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : '../';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include_once($phpbb_root_path . 'common.' . $phpEx);
include_once($phpbb_root_path . 'sv_common.' . $phpEx);


$app_id = get_fb_app_id();
$canvas_page = get_fb_app_url();

$mode				= request_var('mode', '');
$followee_user_id	= request_var('followee_user_id', '');

if ($mode == 'follow')
{
	// Start session management
	$user->session_begin();
	$auth->acl($user->data);

//	$user_id 	= $user->data['user_id'];

//	$uri = append_sid("$canvas_page/follow.php" , "followee_user_id=$followee_user_id");
	$uri = $canvas_page . 'follow.php?followee_user_id=' . $followee_user_id . '&sid=' . $_SID;
	
	$auth_url = "http://www.facebook.com/dialog/oauth?client_id=" 
            . $app_id . "&redirect_uri=" . urlencode($uri) . '&scope=email';
	
}
else if ($mode == 'self_close')
{

	echo("<script> self.close()</script>");	
	return;
}
else
{
	$auth_url = "http://www.facebook.com/dialog/oauth?client_id=" 
            . $app_id . "&redirect_uri=" . urlencode($canvas_page);
}

echo("<script> top.location.href='" . $auth_url . "'</script>");
 
?>